package cn.shlbysj.demo.controller;

import cn.shlbysj.demo.common.ConstansUtil;
import cn.shlbysj.demo.common.PageResult;
import cn.shlbysj.demo.common.Result;
import cn.shlbysj.demo.entity.ArtInfo;
import cn.shlbysj.demo.entity.NewsInfo;
import cn.shlbysj.demo.entity.OnlineExp;
import cn.shlbysj.demo.entity.VideoInfo;
import cn.shlbysj.demo.service.IArticleService;
import cn.shlbysj.demo.service.INewsInfoService;
import cn.shlbysj.demo.service.IOnlineExpService;
import cn.shlbysj.demo.service.IVideoInfoService;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/index")
@Api("首页模块")
public class PageController {

    @Autowired
    private IArticleService articleService;
    @Autowired
    private IOnlineExpService onlineExpService;
    @Autowired
    private IVideoInfoService videoInfoService;
    @Autowired
    private INewsInfoService newsInfoService;

    @RequestMapping(value = "/listByType",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "根据类型获取毕设前列表")
    @ResponseBody
    public Result listByType(HttpServletRequest request,
                       @ApiParam(name="type",value="类型",required = true)@RequestParam(value = "type",required = true) Integer type){
        try {
            List<ArtInfo> list=articleService.getListByType(type);
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }

    }
    @RequestMapping(value = "/getOnlineList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "获取在线体验毕设的列表(6条)")
    @ResponseBody
    public Result getOnlineList(HttpServletRequest request){
        try {
            List<OnlineExp> list=onlineExpService.getList();
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }

    }
    @RequestMapping(value = "/getVideoList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "获取视频的列表(6条)")
    @ResponseBody
    public Result getVideoList(HttpServletRequest request){
        try {
            List<VideoInfo> list=videoInfoService.getList();
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }

    }
    @RequestMapping(value = "/getNewsList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "获取资讯的列表(4条)")
    @ResponseBody
    public Result getNewsList(HttpServletRequest request){
        try {
            List<NewsInfo> list=newsInfoService.getList();
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }

    }
    @RequestMapping(value = "/getNewArtList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "最新的毕设列表(6条)")
    @ResponseBody
    public Result getNewArtList(HttpServletRequest request){
        try {
            PageResult page=articleService.findPage(null,null,0,6);
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(page.getRows()),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }
    }
    @RequestMapping(value = "/getFanArtList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "推荐的毕设列表(6条)")
    @ResponseBody
    public Result getFanArtList(HttpServletRequest request){
        try {
            List<ArtInfo> list=articleService.getListFan();
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }
    }
    @RequestMapping(value = "/getHotArtList",method = RequestMethod.GET)
    @ApiOperation(httpMethod = "GET", value = "热门的毕设列表(6条)")
    @ResponseBody
    public Result getHotArtList(HttpServletRequest request){
        try {
            List<ArtInfo> list=articleService.getListHot();
            return new Result(ConstansUtil.RESULT_SUCCESS,ConstansUtil.RESULT_SUCCESS_MESSAGE, JSON.toJSONString(list),"");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ConstansUtil.RESULT_FAIL,ConstansUtil.RESULT_FAIL_MESSAGE,"","");
        }
    }
}
